Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of methods that modify the network location #1316

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Oct 17, 2024

Avoid calling SplitResult._replace since its much slower, and instead replace with fast NamedTuple creation tuple.__new__(Type, (...)

Copy link

codspeed-hq bot commented Oct 17, 2024

CodSpeed Performance Report

Merging #1316 will improve performances by 63.58%

Comparing with_user (53a818f) with master (96649e7)

Summary

⚡ 4 improvements
✅ 72 untouched benchmarks

Benchmarks breakdown

Benchmark master with_user Change
test_url_with_host 1,117.8 µs 742.8 µs +50.48%
test_url_with_password 975.9 µs 604.5 µs +61.44%
test_url_with_port 957.7 µs 585.5 µs +63.58%
test_url_with_user 972.3 µs 597.3 µs +62.78%

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.94%. Comparing base (96649e7) to head (53a818f).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1316   +/-   ##
=======================================
  Coverage   95.94%   95.94%           
=======================================
  Files          27       27           
  Lines        5373     5378    +5     
  Branches      326      326           
=======================================
+ Hits         5155     5160    +5     
  Misses        192      192           
  Partials       26       26           
Flag Coverage Δ
CI-GHA 95.94% <100.00%> (+<0.01%) ⬆️
MyPy 44.54% <100.00%> (+0.05%) ⬆️
OS-Linux 99.31% <100.00%> (+<0.01%) ⬆️
OS-Windows 99.37% <100.00%> (+<0.01%) ⬆️
OS-macOS 99.04% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 99.01% <100.00%> (+<0.01%) ⬆️
Py-3.10.15 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.11.10 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 99.01% <100.00%> (+<0.01%) ⬆️
Py-3.12.7 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.13.0 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 98.97% <100.00%> (+<0.01%) ⬆️
Py-3.9.20 99.22% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 99.27% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.17 99.29% <100.00%> (+<0.01%) ⬆️
VM-macos-latest 99.04% <100.00%> (+<0.01%) ⬆️
VM-ubuntu-latest 99.31% <100.00%> (+<0.01%) ⬆️
VM-windows-latest 99.37% <100.00%> (+<0.01%) ⬆️
pytest 99.31% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 17, 2024
@bdraco bdraco marked this pull request as ready for review October 17, 2024 23:52
@bdraco bdraco merged commit fcb8d7c into master Oct 17, 2024
43 of 46 checks passed
@bdraco bdraco deleted the with_user branch October 17, 2024 23:52
bdraco added a commit to aio-libs/aiohttp that referenced this pull request Oct 18, 2024
Reuses the same idea as aio-libs/yarl#1316

Calling tuple.__new__ is much faster because it avoids
the extra runtime lambda
https://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441
bdraco added a commit to aio-libs/aiohttp that referenced this pull request Oct 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Reuses the same idea as aio-libs/yarl#1316 and aio-libs/yarl#1322

Calling `tuple.__new__` is much faster because it avoids the extra runtime lambda having to be run and arguments unpacked for every message
https://github.com/python/cpython/blob/d83fcf8371f2f33c7797bc8f5423a8bca8c46e5c/Lib/collections/__init__.py#L441

This only works if the object being created is a `NamedTuple` so this speed up is only recommended internally and should not be used outside of `aiohttp` since we do not guarantee that ConnectionKey will remain a `NamedTuple` in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant